package com.qf.base.controller;

import com.qf.base.domain.BaseAddress;
import com.qf.base.service.IBaseAddressService;
import com.qf.common.annotation.Log;
import com.qf.common.core.controller.BaseController;
import com.qf.common.core.domain.AjaxResult;
import com.qf.common.core.page.TableDataInfo;
import com.qf.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- ONE PIECE ---
 *
 * @author yangjiangcheng
 * @date 2025/9/4
 * @desc
 */
@RestController
@RequestMapping("/tms/base/address")
public class BaseAddressController extends BaseController {
    @Autowired
    private IBaseAddressService baseAddressService;

    /**
     * 获取地址信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseAddress address) {
        startPage();
        List<BaseAddress> list = baseAddressService.selectAddressList(address);
        return getDataTable(list);
    }


    /**
     * 新增地址信息
     */
    @Log(title = "地址管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseAddress address) {
        address.setCreateBy(getUsername());
        return toAjax(baseAddressService.insertAddress(address));
    }

    /**
     * 根据地址Id获取详细信息
     */
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable Long addressId) {
        return success(baseAddressService.selectAddressById(addressId));
    }

    /**
     * 修改地址信息
     */
    @Log(title = "地址管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseAddress address) {
        address.setUpdateBy(getUsername());
        return toAjax(baseAddressService.updateAddress(address));
    }

    /**
     * 删除地址信息
     */
    @Log(title = "地址管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseAddressService.deleteAddressByIds(ids));
    }



}
